<!doctype html>
<html>

	<head>
		<meta charset="utf-8">
		<meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no">
		<meta name="apple-wap-web-app-capable" content="yes">
		<meta name="apple-wap-web-app-status-bar-style" content="black-translucent">
		<title>购物车 </title>
		<script src="__PUBLIC__/Product/js/lib/jquery3.2.1.js"></script>
		<!-- ionic框架  css -->
		<link href="__PUBLIC__/Product/css/weixin.css" rel="stylesheet" type="text/css" />
		<link href="__PUBLIC__/Product/css/ionic.min.css" rel="stylesheet" type="text/css" />
		<link href="__PUBLIC__/Product/css/signin.css" rel="stylesheet" type="text/css" />
		<link href="__PUBLIC__/Product/css/share.css" rel="stylesheet" type="text/css" />
		<!-- ionic框架  js   -->
		<script type="text/javascript" src="__PUBLIC__/Product/js/ionic.bundle.min.js"></script>
		<script src="__PUBLIC__/Product/js/lib/flexible.js"></script>
		<script type="text/javascript">
			//定义全局变量
			var i = 0;
			//金额总和
			var money = 0;
			//计算合计价格
			var cart_money = new Object();
			//全部商品ID
			var cart_id = new Object();
			//备份商品ID，用于全选后去掉全选又再次全选
			var cart_id_copy = new Object();
		</script>
		
		<style type="text/css">
			#collect{
				display: none;
			}
			.kong .img1{
				width: 3.22666666rem;
				height: 3.22666666rem;
				margin-top: 0.8rem;
				margin-left: 3.38666666rem;
			}
			.kong .p1{
				text-align: center;
				margin-top: 0.64rem;
				font-size: 0.48rem;
			}
			.kong .p2{
				text-align: center;
				font-size: 0.37333333rem;
				color: #696969;
				margin-top: 0.13333333rem;
			}
			.kong .img2{
				width: 2.53333333rem;
				height: 0.66666666rem;
				margin-left: 3.73333333rem;
				margin-top: 0.66666666rem;
			}
		</style>
	</head>
	<body>
		<div class="header_box">
			<div class="bar bar-header">
				<div id="tite" class="h1 title" style=" width: 100%; margin: 0 auto; ">购物车</div>
			</div>
		</div>
		<div style="height:44px;"></div>
		<div class="content">
			<!--商品列表-->
			<div class="commodity_box">
				<div class="commodity_list">
					<!--店名信息-->
					<div class="tite_tim select">
						<em aem="1" cart_id="84"></em>
						<span style="color: #A062E0;">零元购</span>
						<div class="clear"></div>
					</div>
					<!--零元购商品-->
					<ul class="commodity_list_term1  commodity_list_term">
					</ul>
				</div>
			</div>
			<div class="commodity_box">
				<div class="commodity_list">
					<!--店名信息-->
					<div class="tite_tim select">
						<em aem="2" cart_id="84"></em>
						<span style="color: #A062E0;">集分兑换</span>
						<div class="clear"></div>
					</div>
					<!--集分兑换商品-->
					<ul class="commodity_list_term2 commodity_list_term">
					</ul>
				</div>
			</div>
			<div class="commodity_box">
				<div class="commodity_list">
					<!--店名信息-->
					<div class="tite_tim select">
						<em aem="3" cart_id="84"></em>
						<span style="color: #A062E0;">集分商城</span>
						<div class="clear"></div>
					</div>
					<!--集分商城商品-->
					<ul class="commodity_list_term3 commodity_list_term">
					</ul>
				</div>
			</div>
			<!-- 商品列表 end -->
		</div>
		<!-- end -->
		<!-- footer -->
		<div style="height:55px;"></div>
		<div class="settle_box">
			<dl class="total_amount">
				<dt><span>应付总额：</span><p id="total_price"><span id="fuhao">￥</span><b>0</b><p id="collect"><span>+</span><span id="jifen">0</span>集分</p></p></dt>
			</dl>
			<input type="hidden" name="gcs" id="gcs" />
			<div class="settle_btn" id="confirm_cart">结算</div>
		</div>
		</div>
		<!-- end -->
		<!--底部-->
		<div class="home_foot">
			<div class="foot_Lt">
				<img class="oldHome" src="__PUBLIC__/Product/img/home.png" alt="" />
				<p>首页</p>
			</div>
			<div class="foot_Con">
				<img class="oldCar" src="__PUBLIC__/Product/img/shop_car2.png" />
				<p>购物车</p>
				<span class="shopingCar_red"><span></span>+</span>
			</div>
			<div class="foot_Rt">
				<img class="oldPerson" src="__PUBLIC__/Product/img/my.png" />
				<p>我的</p>
			</div>
		</div>
		</div>
		</div>
		<div class="mengban"></div>
		<div class="delete">
			<p>确定要删除商品吗?</p>
			<p><img src="__PUBLIC__/Product/img/guanbi.png" alt=""></p>
		</div>
		<div class="yes">
			确定
		</div>
		<!-- 蒙版 -->
		<div class="mask"></div>
		<!-- 提示弹窗 -->
		<div class="errAlert"></div>
		<div class="kong" style="display: none;">
			<img class="img1" src="__PUBLIC__/Product/img/kong_car.png" alt="" />
			<p class="p1">空空的购物车</p>
			<p class="p2">去给自己、给家人买点东西吧~</p>
			<img class="img2" src="__PUBLIC__/Product/img/go_shopping.png" alt="" />
		</div>
	</body>

</html>
<script>
	//将商品信息展示在页面上
	$.ajax({
		type: 'post',
		url: "http://a.91jfk.com/Product/Pointcart/cart_list_data",
		data: {},
		dataType: 'json',
		success: function(res) {
			if(res.code == "1") {
				var msg = res.message.reverse();
				console.log(msg);
				for(var j = 0; j < msg.length; j++) {
					msg[j] == null ? $(".commodity_box:nth-child(" + (j + 1) + ")").css("display", "none") : load(j);
				}
				function load(j) {
					if(j == 0) {
						for(var i = 0; i < msg[j].length; i++) {
							showItem3(msg[j][i].title, msg[j][i].price, msg[j][i].thumbnail, msg[j][i].goods_type, msg[j][i].id, msg[j][i].num,msg[j][i].stock);
						}
					} else if(j == 1) {
						for(var i = 0; i < msg[j].length; i++) {
							showItem2(msg[j][i].sku_name, msg[j][i].cash_price, msg[j][i].show_pic, msg[j][i].goods_type, msg[j][i].id, msg[j][i].shuxing_zhi, msg[j][i].skuid, msg[j][i].point_price, msg[j][i].num,msg[j][i].stock);
						}
					} else if(j == 2) {
						for(var i = 0; i < msg[j].length; i++) {
							showItem1(msg[j][i].sku_name, msg[j][i].cash_price, msg[j][i].show_pic, msg[j][i].goods_type, msg[j][i].id, msg[j][i].shuxing_zhi, msg[j][i].skuid, msg[j][i].num,msg[j][i].stock);
						}
					}
				}
			} else if(res.code == "0"){
				$(".commodity_box").css("display", "none");
				$(".kong").css("display","block");
				$('.kong .img2').bind('click',function(){
					window.location.href = 'http://a.91jfk.com/Product/Pointshop/point_shop_index.html'
				});
			}
			if(($(".commodity_list_term .select").length >= 4)) {
				$(".content").css("padding-bottom", "0");
			}
		},
		error: function(err) {
			console.log(err);
		}
	});
	// 进入购物车页面判断购物车是否有商品
	jduge();
	function jduge(){
		$.ajax({
			type:"post",
			url:"http://a.91jfk.com/Product/Shopindex/ShowCartNum",
			async:true,
			data:{
				classify:1
			},
			dataType:'json',
			success:function(res){
				console.log(res);
				if (res.num == 0) {
					$(".shopingCar_red").hide();
					$('.settle_box').hide();
				} else {
					$(".shopingCar_red").children('span').text(res.num);
				}
			},
			error:function(err){
				console.log(err);
			}
		});
	}
	//集分商城
	function showItem1(title, price, img1, type, id, shuxingzhi, skuid, num,stock) {
		var li = $('<li class="select"></li>');
		var id = $('<div class="id" style="display:none">' + id + '</div>');
		var stock = $('<div class="stock" style="display:none">' + stock + '</div>');
		var skuid = $('<div class="skuid" style="display:none">' + skuid + '</div>');
		var type = $('<div class="type" style="display:none">' + type + '</div>');
		var em = $('<em aem="0" cart_id="84"></em><img src= ' + img1 + ' />');
		var div_left = $('<div class="div_left">' + shuxingzhi + '</div>');
		var div_center = $('<div class="div_center"><p><span>' + title + '</span><span class="edit">编辑</span></p><p><img src="__PUBLIC__/Product/img/delete.png"  class="del" /></p><p class="now_value"><i>￥</i><b class="qu_su">' + price + '</b></p></div>');
		var div_right = $('<div class="div_right"><button value = "-" disabled  onclick="reducew(this)">-</button><span class="zi">' + num + '</span><input type="hidden" value="84"><button value = "+" disabled onclick="plusw(this)">+</button></div>');
		li.append(id).append(stock).append(skuid).append(type).append(em).append(div_center).append(div_left).append(div_right);
		$(".commodity_list_term3").append(li);
	}
	//集分兑换
	function showItem2(title, price, img1, type, id, shuxingzhi, skuid, point, num,stock) {
		var li = $('<li class="select"></li>');
		var id = $('<div class="id" style="display:none">' + id + '</div>');
		var stock = $('<div class="stock" style="display:none">' + stock + '</div>');
		var skuid = $('<div class="skuid" style="display:none">' + skuid + '</div>');
		var type = $('<div class="type" style="display:none">' + type + '</div>');
		var em = $('<em aem="0" cart_id="84"></em><img src= ' + img1 + ' />');
		var div_left = $('<div class="div_left">' + shuxingzhi + '</div>');
		var div_center = $('<div class="div_center"><p><span>' + title + '</span><span class="edit">编辑</span></p><p><img src="__PUBLIC__/Product/img/delete.png"  class="del" /></p><p class="now_value"><i>￥</i><b class="qu_su">' + price + '</b>+<span class="point">' + point + '</span>集分</p></div>');
		var div_right = $('<div class="div_right"><button value = "-" disabled  onclick="reducew(this)">-</button><span class="zi">' + num + '</span><input type="hidden" value="84"><button value = "+" disabled onclick="plusw(this)">+</button></div>');
		li.append(id).append(stock).append(skuid).append(type).append(em).append(div_center).append(div_left).append(div_right);
		$(".commodity_list_term2").append(li);
	}
	//零元购
	function showItem3(title, price, img1, type, id, num,stock) {
		var li = $('<li class="select"></li>');
		var id = $('<div class="id" style="display:none">' + id + '</div>');
		var stock = $('<div class="stock" style="display:none">' + stock + '</div>');
		var type = $('<div class="type" style="display:none">' + type + '</div>');
		var em = $('<em aem="0" cart_id="84"></em><img src= ' + img1 + ' />');
		var div_center = $('<div class="div_center"><p><span>' + title + '</span><span class="edit">编辑</span></p><p><img src="__PUBLIC__/Product/img/delete.png"  class="del" /></p><p class="now_value"><i>￥</i><b class="qu_su">' + price + '</b></p></div>');
		var div_right = $('<div class="div_right"><button  disabled  onclick="reducew(this)">-</button><span class="zi">' + num + '</span><input type="hidden" value="84"><button value = "+" disabled onclick="plusw(this)">+</button></div>');
		li.append(id).append(stock).append(type).append(em).append(div_center).append(div_right);
		$(".commodity_list_term1").append(li);
	}
	var noX = 0; /* 没选中时点击加减计算数量  */
	var allThis = $(".commodity_box .select em"); /*底部全选*/
	/* 减  */
	function reduceMod(e, totalH, pointH) {
		var tn = e.siblings().find(".qu_su").text() - 0; /* 当前选中商品  */
		var tn1 = e.siblings().find(".zi").text() - 0; /* 商品数量  */
		var point = e.siblings().find(".point").text() - 0;
		var finish = e.siblings().find(".over").text();
		if(point) {
			if(finish == "完成") {
				if(pointH == 0) {
					var Point = parseFloat(pointH) - parseFloat(point) * parseFloat(tn1); /* 总价格减该商品总数价格  */
					$("#jifen").text(Point);
				} else {
					var Point = parseFloat(pointH) - parseFloat(point); /* 总价格减该商品总数价格  */
					$("#jifen").text(Point);
				}
			} else {
				if(pointH == 0) {
					var Point = parseFloat(pointH) - parseFloat(point) * parseFloat(tn1); /* 总价格减该商品总数价格  */
					$("#jifen").text(Point);
				} else {
					var Point = parseFloat(pointH) - parseFloat(point) * parseFloat(tn1); /* 总价格减该商品总数价格  */
					$("#jifen").text(Point);
				}
			}
		}
		if(finish == "完成") {
			if(totalH == 0) {
				var Total = parseFloat(totalH) - parseFloat(tn) * parseFloat(tn1); /* 总价格加上该商品总数价格  */
				$("#total_price b").text(Total.toFixed(2));
			} else {
				var Total = parseFloat(totalH) - parseFloat(tn); /* 总价格加上该商品总数价格  */
				$("#total_price b").text(Total.toFixed(2));
			}

		} else {
			if(totalH == 0) {
				var Total = parseFloat(totalH) - parseFloat(tn); /* 总价格加上该商品总数价格  */
				$("#total_price b").text(Total.toFixed(2));
			} else {
				var Total = parseFloat(totalH) - parseFloat(tn) * parseFloat(tn1); /* 总价格加上该商品总数价格  */
				$("#total_price b").text(Total.toFixed(2));
			}
		}
	};
	/* 加  */
	function plusMod(e, totalH, pointH) {
		var tn = e.siblings().find(".qu_su").text() - 0; /* 当前选中商品  */
		var tn1 = e.siblings().find(".zi").text() - 0; /* 商品数量  */
		var point = e.siblings().find(".point").text() - 0;
		var point = e.siblings().find(".point").text() - 0;
		var finish = e.siblings().find(".over").text();
		if(point) {
			if(finish == "完成") {
				if(pointH == 0) {
					var Point = parseFloat(pointH) + parseFloat(point) * parseFloat(tn1); /* 总价格加该商品总数价格  */
					$("#jifen").text(Point);
				} else {
					var Point = parseFloat(pointH) + parseFloat(point); /* 总价格加该商品总数价格  */
					$("#jifen").text(Point);
				}

			} else {
				if(pointH == 0) {
					var Point = parseFloat(pointH) + parseFloat(point) * parseFloat(tn1); /* 总价格加该商品总数价格  */
					$("#jifen").text(Point);
				} else {
					var Point = parseFloat(pointH) + parseFloat(point) * parseFloat(tn1); /* 总价格加该商品总数价格  */
					$("#jifen").text(Point);
				}

			}
		}
		if(finish == "完成") {
			if(totalH == 0) {
				var Total = parseFloat(totalH) + parseFloat(tn) * parseFloat(tn1); /* 总价格加上该商品总数价格  */
				$("#total_price b").text(Total.toFixed(2));
			} else {
				var Total = parseFloat(totalH) + parseFloat(tn); /* 总价格加上该商品总数价格  */
				$("#total_price b").text(Total.toFixed(2));
			}

		} else {
			if(totalH == 0) {
				var Total = parseFloat(totalH) + parseFloat(tn) * parseFloat(tn1); /* 总价格加上该商品总数价格  */
				$("#total_price b").text(Total.toFixed(2));
			} else {
				var Total = parseFloat(totalH) + parseFloat(tn) * parseFloat(tn1); /* 总价格加上该商品总数价格  */
				$("#total_price b").text(Total.toFixed(2));
			}
		}
	};
	/*全选该店商品价格 加*/
	function commodityPlusMod(e, totalH, pointH) {
		var qu = e.parents(".commodity_list").find(".qu_su");
		var quj = e.parents(".commodity_list").find(".zi");
		var point = e.parents(".commodity_list").find(".point");
		var Total = 0;
		var Point = 0;
		var erTotal = true;
		/* 该商品全部金额  */
		for(var i = 0; i < qu.length; i++) {
			var n = qu.eq(i).text();
			var n1 = quj.eq(i).text();
			var point1 = point.eq(i).text();
			/*合计价格*/
			if(erTotal) {
				if(point) {
					Point = parseFloat(pointH) + parseFloat(point1) * parseFloat(n1);
					plus_point = parseFloat(point1) * parseFloat(n1);
					if(Point < 0) {
						Point = 0;
					}
					$("#jifen").text(Point);
				}
				Total = parseFloat(totalH) + (parseFloat(n) * parseFloat(n1));
				plus = parseFloat(n) * parseFloat(n1);
				if(Total < 0)
					Total = 0;

				erTotal = false;
			} else {
				if(point) {

					Point = parseFloat(Point) + (parseFloat(point1) * parseFloat(n1));
					plus_point = parseFloat(point1) * parseFloat(n1);
					if(Point < 0) {
						Point = 0;
					}
					$("#jifen").text(Point);
				}

				Total = parseFloat(Total) + (parseFloat(n) * parseFloat(n1));
				plus = parseFloat(n) * parseFloat(n1);
				if(Total < 0)
					Total = 0;
			}
			$("#total_price b").text(Total.toFixed(2)); /* 合计金额  */
		}
	};
	var plus;
	var plus_point;
	/*全选该店商品价格 减*/
	function commodityReduceMod(e, totalH, pointH) {
		var qu = e.parents(".commodity_list").find(".qu_su");
		var quj = e.parents(".commodity_list").find(".zi");
		var point = e.parents(".commodity_list").find(".point");
		var Total = 0;
		var Point = 0;
		var erTotal = true;
		/* 该商品全部金额  */
		for(var i = 0; i < qu.length; i++) {
			var n = qu.eq(i).text();
			var n1 = quj.eq(i).text();
			var point1 = point.eq(i).text();
			/*合计价格*/
			if(erTotal) {
				if(point) {
					Point = parseFloat(pointH) - (parseFloat(point1) * parseFloat(n1));
					plus_point = parseFloat(point1) * parseFloat(n1);
					if(Point < 0) {
						Point = 0;
					}
					$("#jifen").text(Point);
				}
				Total = parseFloat(totalH) - (parseFloat(n) * parseFloat(n1));
				plus = parseFloat(n) * parseFloat(n1);
				if(Total < 0)
					Total = 0;
				erTotal = false;
			} else {
				if(point) {
					Point = parseFloat(Point) - parseFloat(point1) * parseFloat(n1);
					plus_point = parseFloat(point1) * parseFloat(n1);
					if(Point < 0) {
						Point = 0;
					}
					$("#jifen").text(Point);
				}
				Total = parseFloat(Total) - (parseFloat(n) * parseFloat(n1));
				plus = parseFloat(n) * parseFloat(n1);
				if(Total < 0)
					Total = 0;
			}
			$("#total_price b").text(Total.toFixed(2)); /* 合计金额  */
		}
		return plus;
		return plus_point;
	};
	/*全部商品价格*/
	function commodityWhole() {
		/* 合计金额  */
		var je = $(".commodity_box .select .qu_su"); /* 全部商品单价  */
		var je1 = $(".commodity_box .select .zi"); /* 全部商品数量  */
		var TotalJe = 0;
		for(var i = 0; i < je.length; i++) {
			var n = je.eq(i).text();
			var n1 = je1.eq(i).text();
			TotalJe = TotalJe + (parseFloat(n) * parseFloat(n1));
		}
		$("#total_price b").text(TotalJe.toFixed(2)); /* 合计金额  */
	};
	//选择结算商品
	$(".commodity_list").on("click", ".select em", function() {
		var su = $(this).attr("aem");
		var carts_id = $(this).attr("cart_id");
		var totalH = $("#total_price b").text() - 0; /* 合计金额  */
		var pointH = $("#jifen").text() - 0;
		
		if(su == 0) {
			/* 单选商品  */
			if($(this).siblings(".div_center").find(".point").length > 0){
				$("#collect").css("display","block");
			}
			if($(this).hasClass("pitch_on")) {
				/*去该店全选*/
				$(this).parents("ul").siblings(".select").find("em").removeClass("pitch_on");
				/*去底部全选*/
				$("#all_pitch_on").removeClass("pitch_on");
				$(this).removeClass("pitch_on");
				$("#collect").css("display","none");
				reduceMod($(this), totalH, pointH);
				cart_id[carts_id] = "";
				delete cart_id[carts_id];
			} else {
				$(this).addClass("pitch_on");
				var n = $(this).parents("ul").children().find(".pitch_on");
				var n1 = $(this).parents("ul").children();
				plusMod($(this), totalH, pointH);
				cart_id[carts_id] = "";
				/*该店商品全选中时*/
				if(n.length == n1.length) {
					$(this).parents("ul").siblings(".select").find("em").addClass("pitch_on");
				}
				if($("em[aem=2]").hasClass("pitch_on") && $("em[aem=1]").hasClass("pitch_on") && $("em[aem=2]").hasClass("pitch_on") && $("em[aem=3]").hasClass("pitch_on")) {
					$("#all_pitch_on").addClass("pitch_on");
				}
			}
			//当选中分类的标题时，分类里的商品全部被选中
		} else if(su == 1) {
				$("#collect").css("display","none");
			/* 全选该店铺  */
			if($(this).hasClass("pitch_on")) {
				/*去底部全选*/
				$("#all_pitch_on").removeClass("pitch_on");
				$(this).removeClass("pitch_on");
				commodityReduceMod($(this), totalH, pointH);
				$(this).parent().siblings("ul").find("em").removeClass("pitch_on");
				delete cart_id[carts_id];
			} else {
				$(this).addClass("pitch_on");
				$(this).parent().siblings("ul").find("em").addClass("pitch_on");
				commodityPlusMod($(this), totalH, pointH);
				cart_id[carts_id] = "";
			}

		} else if(su == 2) {
			if($(this).parent(".tite_tim").siblings(".commodity_list_term2").find(".div_center").find(".point").length > 0){
				$("#collect").css("display","block");
			}
			/* 全选该店铺  */
			if($(this).hasClass("pitch_on")) {
				/*去底部全选*/
				$("#all_pitch_on").removeClass("pitch_on");
				$(this).removeClass("pitch_on");
				commodityReduceMod($(this), totalH, pointH);
				$(this).parent().siblings("ul").find("em").removeClass("pitch_on");
				delete cart_id[carts_id];
			} else {
				$(this).addClass("pitch_on");
				$(this).parent().siblings("ul").find("em").addClass("pitch_on");
				commodityPlusMod($(this), totalH, pointH);
				cart_id[carts_id] = "";
			}

		} else if(su == 3) {
				$("#collect").css("display","none");
			/* 全选该店铺  */
			if($(this).hasClass("pitch_on")) {
				/*去底部全选*/
				$("#all_pitch_on").removeClass("pitch_on");
				$(this).removeClass("pitch_on");
				commodityReduceMod($(this), totalH, pointH);
				$(this).parent().siblings("ul").find("em").removeClass("pitch_on");
				delete cart_id[carts_id];
			} else {
				$(this).addClass("pitch_on");
				$(this).parent().siblings("ul").find("em").addClass("pitch_on");
				commodityPlusMod($(this), totalH, pointH);
				cart_id[carts_id] = "";
			}
		}
		//计算选择数值
		number();
	});
	/* 底部全选  */
	var bot = 0;
	$("#all_pitch_on").click(function() {
		if(bot == 0) {
			$(this).addClass("pitch_on");
			allThis.removeClass("pitch_on");
			allThis.addClass("pitch_on");
			/*总价格*/
			commodityWhole();
			bot = 1;
			//重新加入属性对象
			for(var key in cart_id_copy) {
				cart_id[key] = "";
			}
		} else {
			$(this).removeClass("pitch_on");
			allThis.removeClass("pitch_on");
			$("#total_price b").text("0");
			bot = 0;
			//移除全部对象
			for(var key in cart_id) {
				delete cart_id[key];
			}
		}
		//计算选择数值
		number();
	});

	function number() {
		var num = 0;
		for(var key in cart_id) {
			num++;
		}
	}
	/* 加减  */
	function reducew(obj) {
		//减
		var $this = $(obj);
		var totalH = $("#total_price b").text(); /* 合计金额  */
		var pointH = $("#jifen").text();
		var ise = $this.siblings("span").text();
		var gc_id = $this.siblings("input").val();
		if(noX <= 0) {
			noX = 0;
		} else {
			noX--;
		};
		if(parseInt(ise) <= 1) {
			$this.siblings("span").text("1");
		} else {
			var n = parseInt(ise) - 1;
			$this.siblings("span").text(n);
			if($this.parent().parent().children("em").hasClass("pitch_on")) {
				var mo = $this.parent().parent().children("em");
				reduceMod(mo, totalH, pointH, noX);
				noX = 0;
			}
		}
	};
	function plusw(obj) {
		//加
		var $this = $(obj);
		var totalH = $("#total_price b").text(); /* 合计金额  */
		var pointH = $("#jifen").text();
		var ise = $this.siblings("span").text();
		var gc_id = $this.siblings("input").val();
		var n = parseInt(ise) + 1;
		var stock = $this.parents(".div_right").siblings(".stock").text();
		if(n > stock){
			n = stock;
			alert("超出库存");
			
		}
		noX++;
		$this.siblings("span").text(n);
		if($this.parent().parent().children("em").hasClass("pitch_on")) {
			var mo = $this.parent().parent().children("em");
			plusMod(mo, totalH, pointH, noX);
			noX = 0;
		}
	}
	//点击删除图片弹框显示
	$('.commodity_list_term').on("click", ".del", function() {
		$(".mengban").css("display", "block");
		$(".delete").css("display", "block");
		$(".yes").css("display", "block");
		var goods_type = $(this).parents(".select").find(".type").text();
		var id = $(this).parents(".select").find(".id").text();
		console.log(id);
		//点击确定按钮，发送ajax请求，进行删除
		$(".yes").bind("click", function() {
			$.ajax({
				type: "post",
				url: "http://a.91jfk.com/Product/Pointcart/del_one_goods",
				data: {
					id: id,
					model: goods_type
				},
				datatype: "json",
				success: function(xhr) {
					console.log(xhr);
					var data = JSON.parse(xhr);
					console.log(data);
					if(data.code == "1") {
						$(".mengban").css("display", "none");
						$(".delete").css("display", "none");
						$(".yes").css("display", "none");
						setTimeout(function() {
							window.location.href = window.location.href + "?id=" + 10000 * Math.random();
						}, 500);
					} else {
						setTimeout(function() {
							window.location.href = window.location.href + "?id=" + 10000 * Math.random();
						}, 500);
					}
				}
			})
		});
	});
	//点击取消，蒙版消失，弹框消失
	$(".delete p:last-child").bind("click", function() {
		$(".mengban").css("display", "none");
		$(".delete").css("display", "none");
		$(".yes").css("display", "none");
	});
	//点击编辑和完成
	$(".commodity_list_term").on("click", ".edit", function() {
		$(this).text("完成").removeClass("edit").addClass("over");
		$(this).parents(".div_center").find(".del").css("display", 'block');
		$(this).parents(".select").find(".div_right").find("button").prop("disabled", false);
		$(this).parents(".div_center").siblings(".div_right").find("input").prop("disabled", false);
		//点击完成时保存文档
		$(".commodity_list_term").on("click", ".over", function() {
			var goods_type = $(this).parents(".select").find(".type").text();
			var id = $(this).parents(".select").find(".id").text();
			var number = $(this).parents(".select").find(".div_right").find(".zi").text() - 0;
			$.ajax({
				type: "post",
				url: "http://a.91jfk.com/Product/Pointcart/edit_goods_num",
				data: {
					id: id,
					num: number
				},
				datatype: "json",
				success: function(xhr) {
					var data = JSON.parse(xhr);
					console.log(data);
					if(data.code == "1") {
						setTimeout(function() {
							location.reload();
						}, 500);
					} else {
						setTimeout(function() {
							location.reload();
						}, 500);
					}
				}
			})
		});
	});

	$("#confirm_cart").on("click", function() {
		var pitch_on = $('.pitch_on').length;
		var em = $('em').length;
		if(pitch_on == em) {
			alert("全选不能结算");

		} else if($('em[aem = 1]').hasClass("pitch_on") && $('em[aem = 2]').hasClass("pitch_on") || $('em[aem = 1]').hasClass("pitch_on") && $('em[aem = 3]').hasClass("pitch_on") || $('em[aem = 2]').hasClass("pitch_on") && $('em[aem = 3]').hasClass("pitch_on")) {
			alert("多选不能结算");
		} else if($(".commodity_box:nth-child(1) .pitch_on").length > 0 && $(".commodity_box:nth-child(2) .pitch_on").length > 0) {
			alert("多选不能结算");
		} else if($(".commodity_box:nth-child(1) .pitch_on").length > 0 && $(".commodity_box:nth-child(3) .pitch_on").length > 0) {
			alert("多选不能结算");
		} else if($(".commodity_box:nth-child(2) .pitch_on").length > 0 && $(".commodity_box:nth-child(3) .pitch_on").length > 0) {
			alert("多选不能结算");
		} else {
			var storage = window.localStorage;
			var total;
			var pointH;
			var arr = [];
			var a = $(this).parents("body").children(".content").find(".commodity_box").find(".commodity_list_term li").find('.pitch_on');
			for(var i = 0; i < a.length; i++) {
				var obj = {
					goods_type,
					title,
					price,
					num,
					img,
					id,
					skuid,
					shuxingzhi,
					point
				}
				var goods_type = $(a[i]).siblings(".type").text();
				var title = $(a[i]).siblings(".div_center").find(' p span:first-child').text();
				var price = $(a[i]).siblings(".div_center").find(".qu_su").text();
				var num = $(a[i]).siblings(".div_right").find(".zi").text();
				var img = $(a[i]).siblings("img").attr("src");
				var id = $(a[i]).siblings(".id").text();
				var skuid = $(a[i]).siblings(".skuid").text();
				var shuxingzhi = $(a[i]).siblings(".div_left").text();
				var point = $(a[i]).siblings(".div_center").find(".point").text();

				obj.goods_type = goods_type;
				obj.title = title;
				obj.price = price;
				obj.num = num;
				obj.img = img;
				obj.id = id;
				if(obj.goods_type == 1) {
					obj.shuxingzhi = shuxingzhi;
					obj.skuid = skuid;
					arr.push(obj);
					total = $("#total_price b").text();
					window.location.href = "confirmOrder_mall.html";
				} else if(obj.goods_type == 2) {
					obj.point = point;
					obj.shuxingzhi = shuxingzhi;
					obj.skuid = skuid;
					arr.push(obj);
					total = $("#total_price b").text();
					pointH = $("#jifen").text();
					var rag = window.localStorage;
					rag.setItem("ragH", pointH);
					console.log(pointH);
					window.location.href = "confirmOrder_exchange.html";
				} else if(obj.goods_type == 3) {
					arr.push(obj);
					total = $("#total_price b").text();
					window.location.href = "confirmOrder_zero.html";
				}
			}
			arr.push(total);
			var d_zero = JSON.stringify(arr);
			storage.setItem("data_zero", d_zero);
			if($('em[aem = 1]').hasClass("pitch_on")) {
				var a = $(this).parents("body").children(".content").find(".commodity_box").find(".commodity_list_term1 li");
				var arr = [];
				for(var i = 0; i < a.length; i++) {
					var obj = {
						goods_type,
						title,
						price,
						num,
						img,
						id
					}
					var goods_type = $(a[i]).find(".type").text();
					var title = $(a[i]).find(".div_center p span:first-child").text();
					var price = $(a[i]).find(".div_center").find(".qu_su").text();
					var num = $(a[i]).find(".div_right").find(".zi").text();
					var img = $(a[i]).find("img").attr("src");
					var id = $(a[i]).find(".id").text();
					obj.goods_type = goods_type;
					obj.title = title;
					obj.price = price;
					obj.num = num;
					obj.img = img;
					obj.id = id;
					arr.push(obj);
				}
				var total = $("#total_price b").text();
				arr.push(total);
				var d = JSON.stringify(arr);
				storage.setItem("data_title", d);
				window.location.href = "confirmOrder_zero.html";
			} else if($('em[aem = 2]').hasClass("pitch_on")) {

				var a = $(this).parents("body").children(".content").find(".commodity_box").find(".commodity_list_term2 li");
				var arr = [];
				for(var i = 0; i < a.length; i++) {
					var obj = {
						goods_type,
						title,
						price,
						num,
						img,
						id,
						skuid,
						shuxingzhi,
						point
					}
					var goods_type = $(a[i]).find(".type").text();
					var title = $(a[i]).find(".div_center p span:first-child").text();
					var price = $(a[i]).find(".div_center").find(".qu_su").text();
					var num = $(a[i]).find(".div_right").find(".zi").text();
					var img = $(a[i]).find("img").attr("src");
					var id = $(a[i]).find(".id").text();
					var skuid = $(a[i]).find(".skuid").text();
					var shuxingzhi = $(a[i]).find(".div_left").text();
					var point = $(a[i]).find(".div_center").find(".point").text();
					obj.goods_type = goods_type;
					obj.title = title;
					obj.price = price;
					obj.num = num;
					obj.img = img;
					obj.id = id;
					obj.skuid = skuid;
					obj.shuxingzhi = shuxingzhi;
					obj.point = point;
					arr.push(obj);
				}
				var total = $("#total_price b").text();
				var pointH = $("#jifen").text();
				console.log(pointH);
				var sto = window.localStorage;;
				arr.push(total);
				var d = JSON.stringify(arr);
				storage.setItem("data_title", d);
				storage.setItem("point", pointH);
				window.location.href = "confirmOrder_exchange.html";

			} else if($('em[aem = 3]').hasClass("pitch_on")) {

				var a = $(this).parents("body").children(".content").find(".commodity_box").find(".commodity_list_term3 li");
				var arr = [];
				for(var i = 0; i < a.length; i++) {
					var obj = {
						goods_type,
						title,
						price,
						num,
						img,
						id,
						skuid,
						shuxingzhi
					}
					var goods_type = $(a[i]).find(".type").text();
					var title = $(a[i]).find(".div_center p span:first-child").text();
					var price = $(a[i]).find(".div_center").find(".qu_su").text();
					var num = $(a[i]).find(".div_right").find(".zi").text();
					var img = $(a[i]).find("img").attr("src");
					var id = $(a[i]).find(".id").text();
					var skuid = $(a[i]).find(".skuid").text();
					var shuxingzhi = $(a[i]).find(".div_left").text();
					console.log(skuid);
					obj.goods_type = goods_type;
					obj.title = title;
					obj.price = price;
					obj.num = num;
					obj.img = img;
					obj.id = id;
					obj.skuid = skuid;
					obj.shuxingzhi = shuxingzhi;
					arr.push(obj);
				}

				var total = $("#total_price b").text();
				arr.push(total);
				var d = JSON.stringify(arr);
				storage.setItem("data_title", d);
				window.location.href = "confirmOrder_mall.html";
			} else if($(".pitch_on").length == 0) {
				alert("没选商品,请选择商品");
			}

		}
	});

	function alert(a) {
		$('.mask').css('display', 'block');
		setInterval(function() {
			$('.mask').css('display', 'none');
		}, 1000);
		$(".errAlert").text(a).addClass("AlertShow");
	}
</script>

<script>
	$('.foot_Lt').bind('click', function() {
		var str = "{:U('Shopindex/index')}";
		window.location.href = str;
	});
	$('.foot_Rt').bind('click', function() {
		var str = "{:U('User/user')}";
		window.location.href = str;
	});
</script>